<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE root PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

	<h:outputText rendered="#{bairroBean.saveState}">
		<div class="innerTitle">Cadastro de Bairro</div>
	</h:outputText>

	<h:outputText rendered="#{bairroBean.updateState}">
		<div class="innerTitle">Atualização de Bairro</div>
	</h:outputText>

	<h:inputHidden value="#{bairroBean.entity.id}" rendered="#{bairroBean.updateState}"/>
	<h:inputHidden value="#{bairroBean.entity.estado.id}" rendered="#{bairroBean.updateState}"/>

	 <rich:tabPanel switchType="client">

		<rich:tab label="Cadastro">

			<h:panelGrid columns="3" styleClass="crud" columnClasses="label">

				<h:outputLabel value="Nome :"/>
				<h:inputText id="nomeBairro" value="#{bairroBean.entity.nome}" required="true" maxlength="30" size="30">
					<f:validateLength maximum="50"/>
					<rich:ajaxValidator event="onblur"/>
				</h:inputText>
				<rich:message errorClass="error" for="nomeBairro"/>

				<h:outputLabel value="Estado :"/>
				<h:selectOneMenu id="estadoBairro" value="#{bairroBean.entity.estado.id}">
		 				<f:selectItems value="#{estadoBean.listaEstados}"/>
					<a4j:support event="onchange" action="#{bairroBean.populate}" reRender="cidadeBairro"/>
				</h:selectOneMenu>
				<rich:message errorClass="error" for="estadoBairro"/>

				<h:outputLabel value="Cidade :"/>
				<h:selectOneMenu id="cidadeBairro" value="#{bairroBean.entity.cidade.id}">
		 				<f:selectItems value="#{bairroBean.cidades}"/>
				</h:selectOneMenu>
				<rich:message errorClass="error" for="cidadeBairro"/>

			</h:panelGrid>

		</rich:tab>

	</rich:tabPanel>

	<br/>

	<a4j:commandButton value="Inserir" type="submit" action="#{bairroBean.save}" styleClass="button" rendered="#{bairroBean.saveState}"  reRender="popup"/>
	<a4j:commandButton value="Atualizar" type="submit" action="#{bairroBean.update}" styleClass="button" rendered="#{bairroBean.updateState}"  reRender="popup"/>
	<a4j:commandButton value="Voltar" type="submit" action="#{bairroBean.search}" styleClass="button" immediate="true"  reRender="popup"/>

</ui:composition>